package com.qxsx.midi.activity.me;

import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.igexin.sdk.PushManager;
import com.qxsx.midi.R;
import com.qxsx.midi.activity.base.BaseActivity;

/**
 * Created by Joney on 2015/9/25.
 */
public class InfoSetActivity extends BaseActivity implements OnClickListener {

    private CheckBox ck_one, ck_two, ck_three; //消息，声音，震动

    public int statue; //状态

    private Context Context;
    private AudioManager manager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_infoset);
        Context = this;
        setTitle("消息提醒");
        setNavBtn(R.mipmap.back, 0);
        findById();
        inItData();
    }

    /**
     * 获取系统状态
     */
    private void inItData() {

        manager =(AudioManager)Context.getSystemService(Context.AUDIO_SERVICE);
        statue = manager.getRingerMode();

        if(0==statue){
            ck_two.setChecked(false);
            ck_three.setChecked(true);
        }else{
            ck_two.setChecked(true);
            ck_three.setChecked(false);
        }
    }

    private void findById() {

        ck_one = (CheckBox) findViewById(R.id.ck_one);
        ck_two = (CheckBox) findViewById(R.id.ck_two);
        ck_three = (CheckBox) findViewById(R.id.ck_three);

        ck_one.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if (isChecked) {
                    PushManager.getInstance().turnOnPush(InfoSetActivity.this);
                } else {
                    PushManager.getInstance().turnOffPush(InfoSetActivity.this);
                }
            }
        });

        ck_two.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    manager.setRingerMode(2);
                } else {
                    manager.setRingerMode(0);
                }
            }
        });

        ck_three.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    manager.setRingerMode(1);
                } else {
                    manager.setRingerMode(2);
                }
            }
        });


    }

    @Override
    protected void HandleTitleBarEvent(TitleBar component, View v) {

        switch (component) {

            case LEFT:
                finish();
                break;

        }
    }

    @Override
    public void onClick(View v) {

    }
}
